//
//  HSLTabBarController.swift
//  HSLMicroBlog
//
//  Created by mac on 15/12/10.
//  Copyright © 2015年 HSL. All rights reserved.
//

import UIKit

class HSLTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //添加自定义tabBar
        let tabBar = HSLTabBar()
        //不能直接对一个只读属性赋值!!改用KVC
//        self.tabBar = HSLTabBar()
        tabBar.composeBtnClosure = {[weak self] in
            print("撰写按钮被点击啦!")
            print(self?.view)
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(HSLHomeViewController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(HSLMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(HSLDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(HSLProfileViewController(), imgName: "tabbar_profile", title: "我")
    }
    
    func addChildViewController(childController: UIViewController, imgName: String, title: String)
    {
        //设置tabBar和navigationBar的标题
        //        childController.tabBarItem.title = title
        //        childController.navigationItem.title = title
        childController.title = title
        
        //设置tabBar图片
        childController.tabBarItem.image = UIImage(named: imgName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
//        //图标下移
//        childController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
        
        //添加子控制器
        addChildViewController(HSLNavigationController(rootViewController: childController))
        
    }
    
}
